import logging
import requests
from api.login_api import Mepsking_Login
from config import Base_Host
class Search_Goods:
    def search_goods(self,spuname,token):
        url=Base_Host+'/api/meps/goodsShow/getGoodsShow?spuName='+spuname
        header_dict={'accessToken':token}
        resp=requests.get(url=url,headers=header_dict)
        # print('搜索商品的接口返回的数据是：{}'.format(resp.json()))
        logging.info('搜索商品的接口返回的数据是：{}'.format(resp.json()))
        return resp
    def spucode(self,spuname,token):
        resp=self.search_goods(spuname,token)
        spucode=resp.json().get('result').get('records')[0].get('spuCode')
        logging.info('获取到的spuCode为：{}'.format(spucode))
        return spucode
    def skuId(self,spuname,token):
        resp = self.search_goods(spuname, token)
        skuId=resp.json().get('result').get('records')[0].get('skuId')
        logging.info('获取到的skuId为：{}'.format(skuId))
        return skuId
    def sellPrice(self,spuname,token):
        resp = self.search_goods(spuname, token)
        sellPrice=resp.json().get('result').get('records')[0].get('sellPrice')
        logging.info('获取到的sellPrice为：{}'.format(sellPrice))
        return sellPrice
if __name__ == '__main__':
    resp=Mepsking_Login()
    json_dict = {"account": "2524726232@qq.com", "password": "8c730e7f3dac741443cd3a57cdb7fd8f", "sourceFrom": "PC"}
    token=resp.token(json_dict)
    goods=Search_Goods()
    goods=goods.search_goods("私奔乐器机翼",token)







